/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sap.web;

import com.sap.entity.Facultad;
import com.sap.entity.Programa;
import com.sap.session.FacultadFacade;
import com.sap.session.ProgramaFacade;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.faces.model.SelectItem;

/**
 *
 * @author Ususario
 */
@Named(value = "programaMB")
@SessionScoped
public class ProgramaMB implements Serializable {
    @EJB
    private FacultadFacade facultadFacade;

    @EJB
    private ProgramaFacade programaFacade;
    
    private Programa actual;
    
    /**
     * Creates a new instance of ProgramaMB
     */
    public ProgramaMB() {
    }

    public Programa getActual() {
        return actual;
    }

    public void setActual(Programa actual) {
        this.actual = actual;
    }

    public String preparedCreate() {
        actual = new Programa();
        return "crear?faces-redirect=true";
    }

    public String preparedEdit(Programa p) {
        actual = p;
        return "editar?faces-redirect=true";
    }

    public String listPrograma() {
        return "listar?faces-redirect=true";

    }

    public String editPrograma() {
        programaFacade.edit(actual);
        return "listar?faces-redirect=true";
    }

    public String createPrograma() {
        programaFacade.create(actual);
        return "listar?faces-redirect=true";
    }

    public List<Programa> getListPrograma() {
        return programaFacade.findAll();
    }
    
     /**
 * Returns an array of SelectItem to be displayed in the DiscountCode
 * Dropdown list in the CustomerDetails page
 * @return
 */
public javax.faces.model.SelectItem[] getFacultades()
    {
        SelectItem[] options = null;
        List<Facultad> facultades = facultadFacade.findAll();
        if (facultades != null && facultades.size() > 0)
        {
            int i = 0;
            options = new SelectItem[facultades.size()];
            for (Facultad dc : facultades)
            {
                options[i++] = new SelectItem(dc.getId(),
                        dc.getNombre());
            }
        }
        return options;
    }



}
